<?php
include_once("../includes/common.php");
include_once("../class/User.class.php");
include_once("../class/Sys.class.php");
require_once("../islogin.php");

if ($isadmin!=1){
    header('Location: /');
    exit;
}

$menuavatar = !$user_info["message"]["avatar"] ? "/data/avatar/default.jpg" : $user_info["message"]["avatar"];
$pageName = "网站设置";
$sys = new Sys();
$res = json_decode($sys->SysConfig(),true);


if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $data = [
        'web_desc' => $_POST['desc'],
        'web_keywords' => $_POST['key'],
        'create_time' => $_POST['ctime'],
        'contact' => $_POST['contact'],
        'ai_check' => isset($_POST['ai_check']) ? 1 : 0,
    ];
    
    $sys->updateSetting($data);
    header("Location: setting.php");
    exit();
}

?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>

    <?php require_once('head.php'); ?>

    <link rel="stylesheet" href="/static/css/message.css" />
</head> 
<body>
    
<!--==================== Preloader Start ====================-->
  <div class="preloader">
    <div class="loader"></div>
  </div>
<!--==================== Preloader End ====================-->

<!--==================== Sidebar Overlay End ====================-->
<div class="side-overlay"></div>
<!--==================== Sidebar Overlay End ====================-->


<?php require_once('menu.php'); ?>
    <div class="dashboard-main-wrapper">

        <?php require_once('top_navbar.php'); ?>
        <div class="dashboard-body">

            <div class="card">
                <div class="card-header border-bottom">
                    <h4 class="mb-4">网站设置</h4>
                    <p class="text-gray-600 text-15">配置、控制网站信息设置 ~</p>
                </div>
                <div class="card-body">
                    <form action="?save" method="post">
                        <div class="row gy-4">
                            <div class="col-sm-6 col-xs-6">
                                <label for="fname" class="form-label mb-8 h6">网站描述</label>
                                <input type="text" required maxlength="255" value="<?php echo $res['web_desc']?>" name="desc" class="form-control py-11" id="fname" placeholder="输入网站描述">
                            </div>
                            <div class="col-sm-6 col-xs-6">
                                <label for="phone" class="form-label mb-8 h6">网站关键词</label>
                                <input required value="<?php echo $res['web_keywords']?>" type="text" name="key" class="form-control py-11" id="phone" placeholder="输入网站关键词">
                            </div>
                            <div class="col-sm-6 col-xs-6">
                                <label for="role" class="form-label mb-8 h6">网站创建时间</label>
                                <input required value="<?php echo date('Y-m-d', $res['create_time']);?>" type="date" name="ctime" class="form-control py-11" id="role" placeholder="输入网站创建时间">
                            </div>
                            <div class="col-sm-6 col-xs-6">
                                <label for="zip" class="form-label mb-8 h6">联系方式</label>
                                <input required value="<?php echo $res['contact']?>" type="text" name="contact" maxlength="255" class="form-control py-11" id="zip" placeholder="输入联系方式">
                            </div>

                            <div class="col-sm-6 col-xs-6">
                                <h6 class="mb-8">AI设置</h6>
                            </div>
                            <div class="col-sm-6 col-xs-6">
                                <div class="form-switch switch-primary d-flex align-items-center gap-8 mb-16">
                                    <input name="ai_check" class="form-check-input" type="checkbox" role="switch" <?php echo ($res['ai_check'] === '1') ? 'checked' : '';?> id="switch1">
                                    <label class="form-check-label line-height-1 fw-medium text-secondary-light" for="switch1">AI审核笔记</label>
                                </div>
                            </div>

                            <div class="col-12">
                                <div class="flex-align justify-content-end gap-8">
                                    <button type="submit" class="btn btn-main rounded-pill py-9">保 存</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>

        <?php require_once('footer.php'); ?>
    </div>

<?php require_once('foot.php'); ?>


    </body>
</html>